package handler

import (
	"SmartLibrary/pkg/jwt"
	"SmartLibrary/pkg/log"
	"github.com/gin-gonic/gin"
)

type Handler struct {
	logger *log.Logger
}

func NewHandler(
	logger *log.Logger,
) *Handler {
	return &Handler{
		logger: logger,
	}
}

// GetUserIdFromCtx 从上下文中获取UserID
func GetUserIdFromCtx(ctx *gin.Context) int64 {
	// 从上下文中获取键为"claims"的值
	v, exists := ctx.Get("claims")
	if !exists {
		return 0
	}
	// 转换为 JWT 中声明的结构体类型，并且返回UserID
	return v.(*jwt.MyCustomClaims).UserId
}
